<template>
	<view>
		<view class="content">
			<view class="list">
				<view class="row">
					<view class="title">头像</view>
					<view class="right"><view class="tis">
					<image :src="user.userImg" mode="aspectFill"></image>
					</view><view class="icon xiangyou"></view></view>
				</view>
				<view class="row">
					<view class="title">昵称</view>
					<view class="right"><view class="tis">{{user.userNickname}}</view><view class="icon xiangyou"></view></view>
				</view>
				<view class="row" @click="toPersonalInformation()">
					<view class="title">个人信息</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view>
				<!-- <view class="row">
					<view class="title">收货地址</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view> -->
				<view class="row" @click="toUpdate()">
					<view class="title">账户安全</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view>
			</view>
			<!-- <view class="list">
				<view class="row">
					<view class="title">通知提醒</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view>
				<view class="row">
					<view class="title">支付设置</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view>
				<view class="row">
					<view class="title">通用</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view>
			</view> -->
			<view class="list">
				<view class="row">
					<view class="title">版本升级</view>
					<view class="right"><view class="tis">v1.0.0</view><view class="icon xiangyou"></view></view>
				</view>
				<!-- <view class="row">
					<view class="title">清除缓存</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view>
				<view class="row">
					<view class="title">问题反馈</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view>
				<view class="row">
					<view class="title">关于商城</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view> -->
				<view class="row" @click="loginOut()">
					<view class="title">退出登录/注销</view>
					<view class="right"><view class="tis"></view><view class="icon xiangyou"></view></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user:{
				}
			};
		},
		onPullDownRefresh() {
		    setTimeout(function () {
		        uni.stopPullDownRefresh();
		    }, 1000);
		},
		onLoad() {
			this.isLogin();
			this.getUserMessage();
		},
		onShow() {
			this.isLogin();
			this.showUserMessage();
		},
		methods: {
			showType(tbIndex){
				this.tabbarIndex = tbIndex;
				this.list = this.orderList[tbIndex];
			},
			toUpdate(){
					uni.navigateTo({
						url:'../update/update'
					})
			},
			toPersonalInformation(){
					uni.navigateTo({
						url:'../personalInformation/personalInformation'
					})
			},
			getUserMessage(){
				this.$req.getUserPersonalInformation().then(res=>{
					if(res.userPhone){
						var reg2=/([0-9]{4})([0-9]{3})([0-9]{4})/;
						res.userPhone = res.userPhone.replace(reg2,"$1***$3");
					}
					if(res.userNickname == null){
						res.userNickname = '游客'+res.userPhone
					}
					if(res.userImg == null){
						res.userImg  = "/static/img/face.jpg"
					}
					this.user = res;
				})
			},
			showUserMessage(){
				try {
						let user = uni.getStorageSync('user');
						if(user){
							if(user.userPhone){
								var reg2=/([0-9]{4})([0-9]{3})([0-9]{4})/;
								user.userPhone = user.userPhone.replace(reg2,"$1***$3");
							}
							if(user.userNickname == null){
								user.userNickname = '游客'+user.userPhone
							}
							if(user.userImg == null){
								user.userImg  = "/static/img/face.jpg"
							}
							this.user = user;
						}
				} catch (e) {
				    this.$utils.msg("连接网络错误，请检查网络是否连接！");
				}
			},
			isLogin(){
					try {
						let token = uni.getStorageSync('token');
					if ( token = '') {
				       uni.reLaunch({
				       	    url: '../../login/login'
				       	});
				    }
				} catch (e) {
				    this.$utils.msg("连接网络错误，请检查网络是否连接！");
				}
			},
			loginOut(){
				uni.showModal({
					title:'提示',
					content:"是否要退出登录？",
					showCancel:true,
					 success: function (res) {
					        if (res.confirm) {
					            try {
					                uni.removeStorageSync('token');
									uni.removeStorageSync('user');
									uni.showLoading({
										title: '登出中...'
									})
									setTimeout(()=>{
									    uni.hideLoading();
										uni.showToast({title: '登出成功',icon:"none"});
									}, 1000);
									setTimeout(()=>{
									    uni.reLaunch({
									    	    url: '../../login/login'
									    	});
									}, 1500);
					            } catch (e) {
									console.log(e);
									uni.showToast({title: '连接网络错误，请检查网络是否连接！',icon:"none"});
					            }
					        } else if (res.cancel) {
					        }
					    },
				})
				
			}
		}
	}
</script>

<style lang="scss">
page{
	background-color: #f3f3f3;	
}

.icon {
	font-size: 30upx;

}
.content{
	padding-bottom: 20upx;
	.list{
		width: 96%;
		padding-left: 4%;
		background-color: #fff;
		margin-bottom: 20upx;
		.row{
			widows: 100%;
			min-height: 90upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: solid 1upx #eee;
			&:last-child{
				border-bottom: none;
			}
			.title{
				font-size: 32upx;
				color: #333;
			}
			.right{
				display: flex;
				align-items: center;
				color: #999;
				.tis{
					font-size: 26upx;
					margin-right: 5upx;
					max-height: 120upx;
					image{
						width: 100upx;
						height: 100upx;
						border-radius: 100%;
						margin: 10upx 0;
					}
				}
				.icon{
					width: 40upx;
					color: #cecece;
				}
			}
			
		}
	}
}

</style>
